package nodelab;

import java.util.List;
import java.util.Observable;
import java.util.Set;

public class NodeInstance extends Observable {
	private List<NodeInstance> data;
	private NodeInstance preNode;
	
	private Set<Node> classes;
	
	public boolean isAfter(NodeInstance preNode) {
		if(preNode != null) {
			return lastNode(preNode) == firstNode(this).preNode;
		} else {
			return false;
		}
	}
	
	private NodeInstance lastNode(NodeInstance n) {
		if(n.data != null && n.data.size() > 0) {
			Object[] objArr = n.data.toArray();
			Object lastNeuron = objArr[objArr.length - 1];
			NodeInstance lstNeuron = (NodeInstance)lastNeuron;
			return lastNode(lstNeuron);
		}
		return n;
	}
	
	private NodeInstance firstNode(NodeInstance n) {
		if(n.data != null && n.data.size() > 0) {
			Object[] objArr = n.data.toArray();
			Object firstNeuron = objArr[0];
			NodeInstance fstNeuron = (NodeInstance)firstNeuron;
			return lastNode(fstNeuron);
		}
		return n;
	}
	
//	private boolean isAfterChildren(NodeInstance preNode) {
//		if(preNode.data != null && preNode.data.size() > 0) {
//			Object[] objArrs = preNode.data.toArray();
//			if(objArrs.length > 0) {
//				Object lastNode = objArrs[objArrs.length - 1];
//				NodeInstance last = (NodeInstance)lastNode;
//				if(preNode == last || isAfterChildren(last)) {
//					return true;
//				}
//			}
//		}
//		return false;
//	}
//	
//	private boolean isChildrenAfter(NodeInstance preNode) {
//		
//	}
//	
//	public boolean isChildrenAfterChildren(NodeInstance preNode) {
//		
//	}
}
